﻿using Core.Framework;
using Microsoft.EntityFrameworkCore;

#nullable disable

namespace Core.DataAccess.Model.iTool.Gateway
{
    public partial class iToolGatewayContext : DbContext
    {
        public iToolGatewayContext()
        {
        }

        public iToolGatewayContext(DbContextOptions<iToolGatewayContext> options)
            : base(options)
        {
        }

        public virtual DbSet<SysMenu> SysMenus { get; set; }
        public virtual DbSet<GatewayRoute> GatewayRoutes { get; set; }
        public virtual DbSet<SysRole> SysRoles { get; set; }
        public virtual DbSet<SysRoleMenu> SysRoleMenus { get; set; }
        public virtual DbSet<SysUser> SysUsers { get; set; }
        public virtual DbSet<SysUserRole> SysUserRoles { get; set; }
        public virtual DbSet<Node> Nodes { get; set; }
        public virtual DbSet<ServiceInstance> ServiceInstances { get; set; }
        public virtual DbSet<iToolServiceConfiguration> iToolServiceConfigurations { get; set; }


        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder
                    // 数据操作日志
                    //.UseLoggerFactory(EFLogger.GetLoggerFactory())
                    //.UseSqlServer(AppSetting.GetConnectionString("iToolGateway"));
#if DEBUG
                    //.UseSqlServer(AppSetting.iToolGatewaySqlString)
                    .UseSqlServer(AppSetting.iToolGatewaySqlString.Replace("127.0.0.1", "1.117.167.53"))
                    // .UseSqlServer(AppSetting.iToolGatewaySqlString)
#else
                    .UseSqlServer(AppSetting.iToolGatewaySqlString)
#endif
                    .AddInterceptors(new QueryWithNoLockDbCommandInterceptor());

                //optionsBuilder.UseSqlServer("Data Source=139.224.23.203,1501;database=iTool.Gateway;uid=sa;pwd=zhuJIAN320");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");

            modelBuilder.Entity<SysMenu>(entity =>
            {
                entity.HasKey(e => e.MenuId)
                    .HasName("PK__Sys_Menu__69E72318C55ED082");

                entity.ToTable("Sys_Menu");

                entity.Property(e => e.MenuId).HasColumnName("Menu_ID");

                entity.Property(e => e.MenuCreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("Menu_CreateTime");

                entity.Property(e => e.MenuIcon)
                    .IsUnicode(false)
                    .HasColumnName("Menu_Icon");

                entity.Property(e => e.MenuIsShow).HasColumnName("Menu_IsShow");

                entity.Property(e => e.MenuName)
                    .HasMaxLength(50)
                    .HasColumnName("Menu_Name");

                entity.Property(e => e.MenuParentId).HasColumnName("Menu_ParentID");

                entity.Property(e => e.MenuUrl)
                    .HasMaxLength(100)
                    .IsUnicode(false)
                    .HasColumnName("Menu_Url");
            });

            modelBuilder.Entity<SysRole>(entity =>
            {
                entity.HasKey(e => e.RoleId)
                    .HasName("PK__Sys_Role__D80AB49B27D1ECD2");

                entity.ToTable("Sys_Role");

                entity.Property(e => e.RoleId).HasColumnName("Role_ID");

                entity.Property(e => e.RoleCreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("Role_CreateTime");

                entity.Property(e => e.RoleIsDelete).HasColumnName("Role_IsDelete");

                entity.Property(e => e.RoleName)
                    .HasMaxLength(50)
                    .HasColumnName("Role_Name");

                entity.Property(e => e.RoleRemark)
                    .HasMaxLength(500)
                    .HasColumnName("Role_Remark");
            });

            modelBuilder.Entity<SysRoleMenu>(entity =>
            {
                entity.HasKey(e => e.RoleMenuId)
                    .HasName("PK__Sys_Role__AC18E4C8A457FD21");

                entity.ToTable("Sys_RoleMenu");

                entity.Property(e => e.RoleMenuId).HasColumnName("RoleMenu_ID");

                entity.Property(e => e.RoleMenuCreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("RoleMenu_CreateTime");

                entity.Property(e => e.RoleMenuMenuIds)
                    .HasMaxLength(2000)
                    .IsUnicode(false)
                    .HasColumnName("RoleMenu_MenuIDs");

                entity.Property(e => e.RoleMenuRoleId).HasColumnName("RoleMenu_RoleID");
            });

            modelBuilder.Entity<SysUser>(entity =>
            {
                entity.HasKey(e => e.UserId)
                    .HasName("PK__Sys_User__206D919008AE5ECD");

                entity.ToTable("Sys_User");

                entity.Property(e => e.UserId).HasColumnName("User_ID");

                entity.Property(e => e.UserCreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("User_CreateTime");

                entity.Property(e => e.UserIsDelete).HasColumnName("User_IsDelete");

                entity.Property(e => e.UserLoginName)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("User_LoginName");

                entity.Property(e => e.UserName)
                    .HasMaxLength(50)
                    .HasColumnName("User_Name");

                entity.Property(e => e.UserParameter)
                    .HasMaxLength(2000)
                    .IsUnicode(false)
                    .HasColumnName("User_Parameter");

                entity.Property(e => e.UserPwd)
                    .HasMaxLength(100)
                    .IsUnicode(false)
                    .HasColumnName("User_Pwd");
            });

            modelBuilder.Entity<SysUserRole>(entity =>
            {
                entity.HasKey(e => e.UserRoleId)
                    .HasName("PK__Sys_User__BCDA352FB77BBC97");

                entity.ToTable("Sys_UserRole");

                entity.Property(e => e.UserRoleId).HasColumnName("UserRole_ID");

                entity.Property(e => e.UserRoleCreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("UserRole_CreateTime");

                entity.Property(e => e.UserRoleRoleId)
                    .HasMaxLength(2000)
                    .IsUnicode(false)
                    .HasColumnName("UserRole_RoleID");

                entity.Property(e => e.UserRoleUserId).HasColumnName("UserRole_UserID");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
